package com.demo.service.serviceImpl;

import com.demo.common.Pager;
import com.demo.common.StringUtil;
import com.demo.dao.TabMoneyShopsDao;
import com.demo.model.TabMoneyShops;
import com.demo.service.TabMoneyShopsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Service
public class TabMoneyShopsServiceImpl implements TabMoneyShopsService {

    @Resource
    private TabMoneyShopsDao dao;

    @Override
    public int total_shops() {
        return dao.total_shops();
    }

    @Override
    public int total_isv_shops() {
        return dao.total_isv_shops();
    }

    @Override
    public void searchPages(TabMoneyShops shop, HttpServletRequest request) {
        String url="tab_money_shops_view?msname="+shop.getMsname()+"&discription="+shop.getDiscription()+"&money="+shop.getMoney();
        int size=20;
        if(StringUtil.isNotEmpty(shop.getMsname()))
            shop.setMsname("%"+shop.getMsname()+"%");

        if(StringUtil.isNotEmpty(shop.getDiscription()))
            shop.setDiscription("%"+shop.getDiscription()+"%");

        if(StringUtil.isNotEmpty(shop.getMoney()))
            shop.setMoney(shop.getMoney());

        int rows=dao.countByExampleSearch(shop);
        int cpage= request.getParameter("pager") == null ? 1 : Integer
                .parseInt(request.getParameter("pager"));
        if(cpage==0) {
            cpage=1;
        }
        String pager= Pager.getPagerStr(url, size, rows, cpage, 1);
        request.setAttribute("pager", pager);
        TabMoneyShops query=new TabMoneyShops(shop.getMsname(),shop.getDiscription(),shop.getMoney(),size*(cpage-1),size,"id","desc");
        List<TabMoneyShops> list=dao.searchByPage(query);
        request.setAttribute("rows",rows);
        request.setAttribute("list", list);
    }

    @Override
    public boolean save(TabMoneyShops s) {
        return dao.save(s);
    }

    @Override
    public TabMoneyShops findById(String id) {
        return dao.findById(id);
    }

    @Override
    public boolean update_is_pic(TabMoneyShops t) {
        return dao.update_is_pic(t);
    }

    @Override
    public boolean update_is_not_pic(TabMoneyShops t) {
        return dao.update_is_not_pic(t);
    }

    @Override
    public void update_isv(TabMoneyShops t) {
        dao.update_isv(t);
    }

    @Override
    public void update_flag(TabMoneyShops t) {
        dao.update_flag(t);
    }

    @Override
    public void update_isdel(String id) {
        dao.update_isdel(id);
    }

    @Override
    public void update_isdel_rec(String id) {
        dao.update_isdel_rec(id);
    }

    @Override
    public void searchPages_del(TabMoneyShops shop, HttpServletRequest request) {
        String url="tab_money_shops_view_del?msname="+shop.getMsname()+"&discription="+shop.getDiscription()+"&money="+shop.getMoney();
        int size=20;
        if(StringUtil.isNotEmpty(shop.getMsname()))
            shop.setMsname("%"+shop.getMsname()+"%");

        if(StringUtil.isNotEmpty(shop.getDiscription()))
            shop.setDiscription("%"+shop.getDiscription()+"%");

        if(StringUtil.isNotEmpty(shop.getMoney()))
            shop.setMoney(shop.getMoney());

        int rows=dao.countByExampleSearch_del(shop);
        int cpage= request.getParameter("pager") == null ? 1 : Integer
                .parseInt(request.getParameter("pager"));
        if(cpage==0) {
            cpage=1;
        }
        String pager= Pager.getPagerStr(url, size, rows, cpage, 1);
        request.setAttribute("pager", pager);
        TabMoneyShops query=new TabMoneyShops(shop.getMsname(),shop.getDiscription(),shop.getMoney(),size*(cpage-1),size,"id","desc");
        List<TabMoneyShops> list=dao.searchByPage_del(query);
        request.setAttribute("rows",rows);
        request.setAttribute("list", list);
    }
}
